package serverImp;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import dao.UserDao;
import daoimp.UserDaoImp;
import entity.User;
import server.UserServer;
import transaction.Transaction;
import transactionimpl.TransactionImpl;

public class UserServerImp implements UserServer
{
    UserDao dao = null;
    Transaction trans = null;
    public UserServerImp()
    {
        dao = new UserDaoImp();
        trans = new TransactionImpl();
    }
    
    public int add(User u)
    {
        int result=-1;
        try
        {
            trans.beginTransaction();
            result= dao.add(u);
            trans.commit();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
            trans.rollback();
        }
        return result;
    }
    
    public int delete(int uid)
    {
        int result=-1;
        try
        {
            trans.beginTransaction();
            result= dao.delete(uid);
            trans.commit();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
            trans.rollback();
        }
        return result;
    }
    
    public int update(User u)
    {
         int result=-1;
        try
        {
            trans.beginTransaction();
            result= dao.update(u);
            trans.commit();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
            trans.rollback();
        }
        return result;
    }
    
    public List query()
    {
        List list=new ArrayList();
        try
        {
            trans.beginTransaction();
            list=dao.query();
            trans.commit();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
            trans.rollback();
        }
        return list;
    }

    public User select(String name)
    {
        User user=new User();
        try
        {
            trans.beginTransaction();
            user=dao.selectName(name);
            trans.commit();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
            trans.rollback();
        }
        return user;
    }

    public List que(String name)
    {
        List list=new ArrayList();
        try
        {
            trans.beginTransaction();
            list=dao.que(name);
            trans.commit();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
            trans.rollback();
        }
        return list;
    }



    
}
